Repository navigation
feat(opencode): TokenPilot adapter for OpenCode - #96
Merged
Xubqpanda merged 3 commits intoOct 2, 2026
Merged
Conversation
Adds an in-process OpenCode v1 server plugin (`components/adapters/opencode`) plus the host glue it uses (`components/adapters/shared/canonical`), built on the shared packages and mirroring the Claude Code adapter. Refs zjunlp#93. - Stabilizer: `experimental.chat.system.transform` (developer target; the user target is not possible in 1.18.33 because messages are transformed first). - Reduction: request-time in `experimental.chat.messages.transform`, through the shared `@lightrsi/reduction` pipeline over a canonical envelope. - Recovery: the shared recovery MCP server, registered in `opencode.json`. - Eviction (opt-in, needs taskStateEstimator settings): the shared canonical-surface cycle, applied as a durable per-session overlay. - Repeat-read rule: as in zjunlp#92, a disclosed path is carried into the next request only when the trimmed read that disclosed it has left the history; the record is saved per session so restarts keep it. - Reversible install with backups (jsonc configs are printed, never rewritten); never writes credentials; every hook fails open and logs to `<stateDir>/tokenpilot/adapter.log`. Tests: 189 in the package. The shared glue (config, reduction, memo store, before-call, eviction, logger) has one test file per module, each listing the cases it covers; plus runtime, codec/overlay, install/doctor and registration tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S6it2Si8k8XNGMF8RdyMQz
`lightrsi opencode status|report|doctor|visual|mode|stabilizer|reduction|eviction` through a small in-process host bridge (hosts/in-process.ts) that reuses the restricted host command handler, so OpenCode gets the same command surface as Claude Code. TOKENPILOT_OPENCODE_CONFIG / TOKENPILOT_OPENCODE_CONFIG_DIR select non-default config locations. Tests: tests/in-process-hosts.test.ts (registration, every command, env overrides). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S6it2Si8k8XNGMF8RdyMQz
- components/adapters/opencode/README.md is in the adapter commit; this adds the design note (docs/adapters/opencode-design.md), the HOSTS.md and adapters README rows, the website host page and compatibility matrix, and the sidebar link. - CI runs the OpenCode adapter suite. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S6it2Si8k8XNGMF8RdyMQz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #93. Adds TokenPilot support for OpenCode, verified on 1.18.33. It builds on the shared eviction core from #95.
Measured benefit
The test used llama-server with Qwen3-1.7B and a 32k context window, running the same scripted coding session with the adapter off and on, from a cold cache.
lightrsi opencode doctorreported healthy after the run.How it plugs in
OpenCode loads plugins in-process, so no proxy is needed.
experimental.chat.system.transformexperimental.chat.messages.transform, which runs before every model stepopencode.jsonmessages.transform, plus a stored per-session overlay. OpenCode has no lasting part-edit hook, so evictions are re-applied identically on every request.Install is reversible. It adds one plugin loader file and exactly one
mcpkey toopencode.json, with a backup. It never rewrites anopencode.jsonc. Uninstall removes only what install added. The adapter is also registered in the shared CLI aslightrsi opencode status|report|doctor|visual|mode|….What's in the 3 commits
components/adapters/opencode/src)components/adapters/shared/canonical/)The shared code sits on #95's eviction core. It handles config, the before-call pipeline, reduction and eviction for hosts that hand over the whole transcript. It also applies the repeat-read rule from #92: a file read stays trimmed while the same read is still in the history.
Known limits (OpenCode 1.18.33)
hooks.dynamicContextTarget=userruns asdeveloper, becausemessages.transformruns beforesystem.transform.doctorreports this.Tests
pnpm build,pnpm typecheckandcheck:boundariespass, and every suite CI runs passes.Prepared with help from Claude Code; the commits are marked
Co-Authored-By: Claude.